/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.pile.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.pile.entity.Pile;
import com.jeesite.modules.pile.service.PileService;

/**
 * 停车桩Controller
 * @author 谢宇燊
 * @version 2020-04-05
 */

@Controller
@RequestMapping(value = "${adminPath}/pile/pile")
public class PileController extends BaseController {

	@Autowired
	private PileService pileService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public Pile get(String id, boolean isNewRecord) {
		return pileService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("pile:pile:view")
	@RequestMapping(value = {"list", ""})
	public String list(Pile pile, Model model) {
		model.addAttribute("pile", pile);
		return "modules/pile/pileList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("pile:pile:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<Pile> listData(Pile pile, HttpServletRequest request, HttpServletResponse response) {
		pile.setPage(new Page<>(request, response));
		Page<Pile> page = pileService.findPage(pile);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("pile:pile:view")
	@RequestMapping(value = "form")
	public String form(Pile pile, Model model) {
		model.addAttribute("pile", pile);
		return "modules/pile/pileForm";
	}

	/**
	 * 保存停车桩
	 */
	@RequiresPermissions("pile:pile:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated Pile pile) {
		pileService.save(pile);
		return renderResult(Global.TRUE, text("保存停车桩成功！"));
	}
	
	/**
	 * 删除停车桩
	 */
	@RequiresPermissions("pile:pile:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(Pile pile) {
		pileService.delete(pile);
		return renderResult(Global.TRUE, text("删除停车桩成功！"));
	}
	
}